package pw.canyingisme.plugin.action;

import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import pw.canyingisme.plugin.config.ConfigLoader;
import pw.canyingisme.plugin.event.onAction;

public class ActionManager {
    public static boolean init(){
        return ActionConfigManager.init();
    }
    public static void ApplyAction(LivingEntity Player,int EventType,String EventName){
        String type;
        type=null;
        if(EventType==1){
            type="Death";
        }if(EventType==2){
            type="Move";
        }if(EventType==3){
            type="Attack";
        }if(EventType==4){
            type="Hurt";
        }if(EventType==0){
            type=EventName;
        }if(EventType==5){
            type="HurtByEntity";
        }if(EventType==6){
            type="HurtByPlayer";
        }if(EventType==7){
            type="HurtByBlock";
        }
        if(type==null){
            return;
        }
            if(ConfigLoader.hasOccupation(Player.getName())){
                if(ConfigLoader.hasActionPack(ConfigLoader.getPlayerOccupation(Player.getName()),type)){
                }else {
                    return;
                }
                if(!ConfigLoader.hasOccupationActionPackPercent(ConfigLoader.getPlayerOccupation(Player.getName()),type)){
                    if(Percent(ConfigLoader.getOccupationActionPackPercent(ConfigLoader.getPlayerOccupation(Player.getName()),type))){
                    }else {
                        return;
                    }
                }
                ActionConfigManager
                        .getActionList( ConfigLoader
                                .getOccupationActionPack( ConfigLoader
                                        .getPlayerOccupation(Player.getName()),type))
                        .forEach((Action) -> ApplyAction(Player, Action.toString()));
            }else {
                //没有职业
            }
    }
    public static void ApplyAction(LivingEntity Player,String Action){
        if(Action.equalsIgnoreCase("tntboom")){
            ActionList.ApplyTntBoom(Player);
            return;
        }if(Action.equalsIgnoreCase("addFoodLevel")){
            ActionList.addFood(Player);
            return;
        }if(Action.equalsIgnoreCase("removeFoodLevel")){
            ActionList.removeFood(Player);
            return;
        }if(Action.equalsIgnoreCase("addHealth")){
            ActionList.addHealth(Player);
            return;
        }if(Action.equalsIgnoreCase("removeHealth")){
            ActionList.removeHealth(Player);
            return;
        }if(Action.equalsIgnoreCase("Speed15s")){
            ActionList.run15s(Player);
            return;
        }if(Action.equalsIgnoreCase("Speed30s")){
            ActionList.run30s(Player);
            return;
        }
        onAction event = new onAction(Player,Action);
        Bukkit.getServer().getPluginManager().callEvent(event);
    }
    public static boolean Percent(int Percent){
        if(Percent==1){
            return true;
        }
        int num = 100/Percent;
        int random = (int)(1+Math.random()*(100-1+1));
        if(num<=random){
            return true;
        }
        return false;
    }
}

